From 1f57e2ca873f37ee4704bcf183a036b5dd1f3af5 Mon Sep 17 00:00:00 2001 From: torkleyy Date: Thu, 11 May 2017 20:47:48 +0200 Subject: [PATCH] Add --exclude flag Allows to exclude packages in conjunction with --all. --- src/bin/build.rs | 13 +++++++++---- src/cargo/ops/cargo_compile.rs | 8 ++++++++ src/cargo/ops/cargo_run.rs | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/bin/build.rs b/src/bin/build.rs index 731d563c9..650e256da 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -31,6 +31,7 @@ pub struct Options { flag_locked: bool, flag_frozen: bool, flag_all: bool, + flag_exclude: Vec, } pub const USAGE: &'static str = " @@ -43,6 +44,7 @@ Options: -h, --help Print this message -p SPEC, --package SPEC ... Package to build --all Build all packages in the workspace + --exclude SPEC ... Exclude packages from the build -j N, --jobs N Number of parallel jobs, defaults to # of CPUs --lib Build only this package's library --bin NAME Build only the specified binary @@ -73,6 +75,7 @@ current package is built. For more information on SPEC and its format, see the All packages in the workspace are built if the `--all` flag is supplied. The `--all` flag may be supplied in the presence of a virtual manifest. +Note that `--exclude` has to be specified in conjunction with the `--all` flag. Compilation can be configured via the use of profiles which are configured in the manifest. The default profile for this command is `dev`, but passing @@ -90,10 +93,12 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; - let spec = if options.flag_all { - Packages::All - } else { - Packages::Packages(&options.flag_package) + let spec = match (options.flag_all, &options.flag_exclude) { + (true, exclude) if exclude.is_empty() => Packages::All, + (true, exclude) => Packages::OptOut(exclude), + (false, exclude) if !exclude.is_empty() => panic!("--exclude can only be used together \ + with --all"), + _ => Packages::Packages(&options.flag_package), }; let opts = CompileOptions { diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 8506a4523..59e9fbcb7 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -105,6 +105,7 @@ pub enum MessageFormat { #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Packages<'a> { All, + OptOut(&'a [String]), Packages(&'a [String]), } @@ -117,6 +118,13 @@ impl<'a> Packages<'a> { .map(PackageIdSpec::from_package_id) .collect() } + Packages::OptOut(opt_out) => { + ws.members() + .map(Package::package_id) + .map(PackageIdSpec::from_package_id) + .filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none()) + .collect() + } Packages::Packages(packages) => { packages.iter().map(|p| PackageIdSpec::parse(&p)).collect::>>()? } diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 47d18a981..e631e503d 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -11,6 +11,7 @@ pub fn run(ws: &Workspace, let pkg = match options.spec { Packages::All => unreachable!("cargo run supports single package only"), + Packages::OptOut(_) => unreachable!("cargo run supports single package only"), Packages::Packages(xs) => match xs.len() { 0 => ws.current()?, 1 => ws.members() -- 2.30.2